<%inherit file="base.html"/>
<%def name="head()">
<script>

function do_pause(account_number)
{
    if (!confirm("确认操作吗？")) {
        return;
    }
    params = {account_number:account_number,'_xsrf': '${handler.xsrf_token}'};
    $.post("/admin/account/pause", params, function (data) {
        alert(data.msg)
        window.location.reload();
    },"json");
}

function do_resume(account_number)
{
    if (!confirm("确认操作吗？")) {
        return;
    }
    params = {account_number:account_number,'_xsrf': '${handler.xsrf_token}'};
    $.post("/admin/account/resume", params, function (data) {
        alert(data.msg)
        window.location.reload();
    },"json");
}    

function release(account_number)
{
    params = {account_number:account_number,'_xsrf': '${handler.xsrf_token}'};
    $.post("/admin/account/release", params, function (data) {
        alert(data.msg)
        location.href.reload();
    },"json");
}

function do_delete(customer_id)
{
    if(confirm("删除账号将删除账号所有相关数据，包括账号，日志，订单等，不可恢复，确认操作吗？")) {
        window.location.href = "/admin/customer/delete?customer_id="+customer_id;
    }
    
}

</script>
</%def>
<%def name="body()">
<section class="content">
    <div class="box box-primary">
        <div class="box-header">
            <i class="fa fa-user"></i>
            <h3 class="box-title">用户受理</h3>
            <div class="bar pull-right"><a href="javascript:history.go(-1);">返回</a></div>
        </div>
        <div class="box-body">
            <div class="container">
        <div class="pull-right">
           <div class="btn-group" role="group" aria-label="...">
               
            % if permit.match(current_user.username,'/admin/account/open'):
            <a href="/admin/account/open?customer_id=${customer.customer_id}" class="btn btn-sm btn-info">新开子账号</a>
            % endif
            
            % if user.status == 2:
           
                % if permit.match(current_user.username,'/admin/account/resume'):
                <a class="btn btn-sm btn-info" href="javascript:do_resume('${user.account_number}');">复机</a>
                % endif
               
            % elif user.status == 1:
            
                % if permit.match(current_user.username,'/admin/customer/update'):
                <a href="/admin/customer/update?customer_id=${customer.customer_id}&account_number=${user.account_number}" class="btn btn-sm btn-info">修改基本资料</a>
                % endif

                % if permit.match(current_user.username,'/admin/account/update'):
                <a class="btn btn-sm btn-info" href="/admin/account/update?account_number=${user.account_number}">修改策略</a>
                % endif

                % if permit.match(current_user.username,'/admin/account/release'):
                <a class="btn btn-sm btn-info" href="javascript:release('${user.account_number}');">释放绑定</a>
                % endif
            
                % if permit.match(current_user.username,'/admin/account/change'):
                <a class="btn btn-sm btn-info" href="/admin/account/change?account_number=${user.account_number}">资费变更</a>
                % endif
               
                % if permit.match(current_user.username,'/admin/account/pause'):
                <a class="btn btn-sm btn-info" href="javascript:do_pause('${user.account_number}');">停机</a>
                % endif
               
                % if user.product_policy in (0,2,3,5):
               
                    % if permit.match(current_user.username,'/admin/account/next'):
                    <a class="btn btn-sm btn-info" href="/admin/account/next?account_number=${user.account_number}">续费</a>
                    % endif
                   
                % elif user.product_policy in (1,4): 
                   
                    % if permit.match(current_user.username,'/admin/account/charge'):
                    <a class="btn btn-sm btn-info" href="/admin/account/charge?account_number=${user.account_number}">充值</a>
                    % endif
                   
                % endif
                   
                % if permit.match(current_user.username,'/admin/account/cancel'):
                <a class="btn btn-sm btn-danger" href="/admin/account/cancel?account_number=${user.account_number}">销户</a>
                % endif
               
            % elif user.status == 4:
           
                % if permit.match(current_user.username,'/admin/account/next'):
                <a class="btn btn-sm btn-info" href="/admin/account/next?account_number=${user.account_number}">续费</a>
                % endif
               
            % endif
            
            % if permit.match(current_user.username,'/admin/account/delete'):
            <a class="btn btn-sm btn-danger" href="javascript:do_delete('${customer.customer_id}');">删除</a>
            % endif
            </div>
        </div>   
        <br> 

        <table class="table">
                <thead>
                    <tr>
                        <th colspan="6"> 基本信息</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>用户姓名</td>
                        <td>${customer.realname}</td>
                        <td>证件号码</td>
                        <td>${customer.idcard}</td>
                        <td>自助服务登陆名</td>
                        <td>${customer.customer_name}</td>                 
                    </tr>
                    <tr>
                        <td>年龄</td>
                        <td>${customer.age}</td>
                        <td>email</td>
                        <td>${customer.email}
                        % if customer.email:
                        (${customer.email_active == 1 and u'已绑定' or u'未绑定'})
                        % endif
                        </td>
                        <td>联系电话</td>
                        <td>${customer.mobile}</td>
                    </tr>      
                    <tr>
                        <td>地址</td>
                        <td>${customer.address}</td>
                        <td>创建时间</td>
                        <td>${customer.create_time}</td>
                        <td>更新时间</td>
                        <td>${customer.update_time}</td>                        
                    </tr>                                                                       
            </tbody>
        </table>
        <table class="table">
                <thead>
                    <tr>
                        <th colspan="6"> 认证信息</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>用户账号(密码)</td>
                        <td>${user.account_number}
                        </td>
                        <td>资费名称</td>
                        <td>${user.product_name}</td>
                        <td>用户状态</td>
                        <td>
                            % if utils.is_expire(user.expire_date) or user.status == 4:
                                <span class="label label-warning">到期</span>
                            % elif user.status == 1:
                                <span class="label label-success">正常</span>
                            % elif user.status == 2:
                                <span class="label label-default">停机</span>
                            % elif user.status == 3:
                                <span class="label label-danger">销户</span>
                            % endif
                        </td>                 
                    </tr>
                    <tr>
                        <td>过期时间</td>
                        <td>${user.expire_date}</td>
                        <td>余额</td>
                        <td>${utils.fen2yuan(user.balance)}</td>
                        <td>剩余时长</td>
                        <td>${utils.sec2hour(user.time_length)}小时</td>
                    </tr>      
                    <tr>
                        <td>剩余流量</td>
                        <td>${utils.kb2mb(user.flow_length)}MB</td>
                        <td>并发数</td>
                        <td>${user.user_concur_number}</td>
                        <td>绑定MAC</td>
                        <td>${{0:u"否", 1:u"是"}[user.bind_mac]}</td>                        
                    </tr>   
                    <tr>
                        <td>绑定VLAN</td>
                        <td>${{0:u"否", 1:u"是"}[user.bind_vlan]}</td>
                        <td>VLANID1/VLANID2</td>
                        <td>${user.vlan_id1}/${user.vlan_id2}</td>
                        <td>MAC地址</td>
                        <td>${user.mac_addr}</td>                        
                    </tr>   
                    <tr>
                        <td>IP地址</td>
                        <td>${user.ip_address}</td>
                        <td>最近停机时间</td>
                        <td>${user.last_pause or ''}</td>
                        <td>创建时间</td>
                        <td>${user.create_time}</td>                        
                    </tr>                                                                      
            </tbody>
        </table>

        <table class="table">
            <thead>
                <tr>
                    <th colspan="6"> 账号受理记录</th>
                </tr>
                <tr class="active">
                    <th>用户账号</th>
                    <th>受理类型</th>
                    <th>操作员</th>
                    <th>受理时间</th>
                    <th>订单号</th>
                    <th>受理描述</th>
                </tr>
            </thead>
            <tbody>
            % for alog in accepts:
            <tr>
                <td>${alog.account_number}</td>
                <td>${type_map[alog.accept_type]}</td>
                <td>${alog.operator_name}</td>
                <td>${alog.accept_time}</td>
                <td>${get_orderid(alog.id) or ''}</td>
                <td>${alog.accept_desc or ''}</td>
            </tr>
            % endfor
            </tbody>
        </table>

        <table class="table ">
            <thead>
                <tr>
                    <th colspan="7"> 账号交易记录</th>
                </tr>
                <tr class="active">
                    <th>订单号</th>
                    <th>资费</th>
                    <th>应缴</th>
                    <th>实缴</th>
                    <th>状态</th>
                    <th>时间</th>
                    <th width=25%>描述</th>
                </tr>
            </thead>
            <tbody>
            % for order in orders:
            <tr>
                <td>${order.order_id}</td>
                <td>${order.product_name}</td>
                <td>${utils.fen2yuan(order.order_fee)}</td>
                <td>${utils.fen2yuan(order.actual_fee)}</td>
                <td>${{0:u"未支付",1:u"已支付",2:u"已取消"}[order.pay_status]}</td>
                <td>${order.create_time}</td>
                <td>${order.order_desc or ''}</td>
            </tr>
            % endfor
            </tbody>
        </table>

    </div>
</div>
</div>
</div>
    </section>
</%def>